<?php

namespace app\common\model\Business;

use think\Model;

/**
 * 客户收货地址模型
 */
class Address extends Model
{
  // 设置当前模型对应的完整数据表名称
  protected $table = 'pre_business_address';

  // 开启自动写入时间戳字段
  protected $autoWriteTimestamp = true;

  // 定义时间戳字段名
  protected $createTime = 'createtime';

  // 关闭自动写入update_time字段
  protected $updateTime = false;

  protected $append = [
    'full_region',//省市区 
  ];

  public function getFullRegionAttr()
  {
      $region = $this->region;
      $fullRegion = $region->province . $region->city . $region->district;
      return $fullRegion;
  }

  // 关联查询省市区表
  public function region()
   {
     return $this->belongsTo('app\common\model\Region','district','code');
   }

}
